package com.yuuzy.controller;

import com.yuuzy.dto.PatientBasicDTO;
import com.yuuzy.dto.PatientPageQueryDTO;
import com.yuuzy.entity.Patient;
import com.yuuzy.result.PageResult;
import com.yuuzy.result.Result;
import com.yuuzy.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 患者信息管理
 */
@RestController
@RequestMapping("/diagnose/patient")
@Slf4j
@Api(tags = "患者信息相关接口")
public class PatientController {

	@Autowired
	private PatientService patientService;

	@PostMapping
	@ApiOperation("新增患者")
	public Result save(@RequestBody PatientBasicDTO patientBasicDTO) {
		log.info("新增患者:{}", patientBasicDTO);
		patientService.save(patientBasicDTO);
		return Result.success();

	}

	/**
	 * 患者分页查询
	 *
	 * @param patientPageQueryDTO
	 * @return
	 */
	@GetMapping("/page")
	@ApiOperation("患者分页查询")
	public Result<PageResult> pageQuery(PatientPageQueryDTO patientPageQueryDTO) {
		log.info("患者分页查询:{}", patientPageQueryDTO);
		PageResult pageResult = patientService.pageQuery(patientPageQueryDTO);
		return Result.success(pageResult);
	}

	/**
	 * 患者批量删除
	 *
	 * @param ids
	 * @return
	 */
	@DeleteMapping
	@ApiOperation("患者批量删除")
	public Result delete(@RequestParam List<Integer> ids) {
		log.info("患者批量删除：{}", ids);
		patientService.deleteBatch(ids);
		return Result.success();
	}

	@GetMapping("/{id}")
	@ApiOperation("根据id查询患者")
	public Result<Patient> selectById(@PathVariable Integer id) {
		log.info("根据id查询患者：{}", id);
		Patient patient = patientService.selectById(id);
		return Result.success(patient);
	}

	/**
	 * 修改患者信息
	 *
	 * @param patient
	 * @return
	 */
	@PutMapping
	@ApiOperation("修改患者信息")
	public Result update(@RequestBody Patient patient) {
		log.info("修改患者信息:{}",patient);
		patientService.update(patient);
		return Result.success();
	}
}
